package com.ymttest.database.sqlwapper;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.ymt.core.tool.FormatUtil;
import com.ymt.database.SqlManager;
import com.ymttest.database.model.*;

public class YmtSellerCSIMWapper {
	SqlManager manage;
	public YmtSellerCSIMWapper() {
		manage = new SqlManager("ymtsellercsim");
	}
	/**
	 * 查询客服在线记录
	 * @param mcsid 主商家账号
	 * @param csid 子账号
	 * @return
	 * @throws InterruptedException
	 */
	public List<YmtOnlinecs> selectYmtOnlinecs(Integer mcsid,Integer csid)
			throws InterruptedException {
		Map m=new HashMap<>();
		m.put("mcsid", mcsid);
		m.put("csid", csid);
		List<YmtOnlinecs> ymt = new ArrayList<YmtOnlinecs>();
		ymt = manage
				.getSelectResults(
						"com.ymttest.database.mapping.YmtSellerCSIMMapper.selectYmtOnlinecs",
						m);
		manage.commit();
		return ymt;
	}
	/**
	 * 删除记录
	 * @param csid
	 * @return
	 * @throws InterruptedException
	 */
	public int deleteYmtOnlinecsByCsid(Integer csid)
			throws InterruptedException {
		Map m=new HashMap<>();
		m.put("csid", csid);
		int n = manage
				.delete(
						"com.ymttest.database.mapping.YmtSellerCSIMMapper.deleteYmtOnlinecsByCsid",
						m);
		manage.commit();
		return n;
	}
	/**更新LoginStatus
	 * @param csid
	 * @param loginStatus
	 * @return
	 * @throws InterruptedException
	 */
	public int updateYmtOnlinecsSetLoginStatus(Integer csid,Integer loginStatus)
			throws InterruptedException {
		Map m=new HashMap<>();
		m.put("csid", csid);
		m.put("ls", loginStatus);
		int n = manage
				.update(
						"com.ymttest.database.mapping.YmtSellerCSIMMapper.updateYmtOnlinecsSetLoginStatus",
						m);
		manage.commit();
		return n;
	}
	/**
	 * 更新YmtOnlinecs的LastActiveTime
	 * @param csid
	 * @param loginStatus
	 * @return
	 * @throws InterruptedException
	 */
	public int updateYmtOnlinecsLastActiveTime(Integer csid,Date LastActiveTime)
			throws InterruptedException {
		Map m=new HashMap<>();
		m.put("csid", csid);
		m.put("LastActiveTime", LastActiveTime);
		int n = manage
				.update(
						"com.ymttest.database.mapping.YmtSellerCSIMMapper.updateYmtOnlinecsLastActiveTime",
						m);
		manage.commit();
		return n;
	}
	
	/**
	 * 插入一个风控用户
	 * @param YmtRiskyuser
	 * @return
	 */
	public int insertYmtRiskyuser(int userId,boolean disable){
		YmtRiskyuser YmtRiskyuser=new YmtRiskyuser();
		YmtRiskyuser.setCreateTime(new Date());
		YmtRiskyuser.setDisabled(disable);
		YmtRiskyuser.setRegisterTime(new Date());
		YmtRiskyuser.setUpdateTime(new Date());
		YmtRiskyuser.setUserId(userId);
		int n = manage
				.insert(
						"com.ymttest.database.mapping.YmtSellerCSIMMapper.insertYmtRiskyuser",
						YmtRiskyuser);
		manage.commit();
		return n;
	}
	
	/**
	 * 查询风控用户
	 * @param uid
	 * @return
	 * @throws InterruptedException
	 */
	public List<YmtRiskyuser> selectYmtRiskyuserByUid(Integer uid)
			throws InterruptedException {
		Map m=new HashMap<>();
		m.put("uid", uid);
		List<YmtRiskyuser> ymt = new ArrayList<YmtRiskyuser>();
		ymt = manage
				.getSelectResults(
						"com.ymttest.database.mapping.YmtSellerCSIMMapper.selectYmtRiskyuserByUid",
						m);
		manage.commit();
		return ymt;
	}
	/**
	 * 更新用户风控状态
	 * @param uid
	 * @param disable
	 * @return
	 * @throws InterruptedException
	 */
	public int updateYmtRiskyuserByUid(Integer uid,Boolean disable)
			throws InterruptedException {
		Map m=new HashMap<>();
		m.put("uid", uid);
		m.put("disable", disable);
		int n = manage
				.update(
						"com.ymttest.database.mapping.YmtSellerCSIMMapper.updateYmtRiskyuserByUid",
						m);
		manage.commit();
		return n;
	}
	/**
	 * 查询风控消息
	 * @param from
	 * @param to
	 * @return
	 * @throws InterruptedException
	 */
	public List<YmtRiskymessage> selectYmtRiskymessage(Integer from,Integer to)
			throws InterruptedException {
		Map m=new HashMap<>();
		m.put("from", from);
		m.put("to", to);
		List<YmtRiskymessage> ymt = new ArrayList<YmtRiskymessage>();
		ymt = manage
				.getSelectResults(
						"com.ymttest.database.mapping.YmtSellerCSIMMapper.selectYmtRiskymessage",
						m);
		manage.commit();
		return ymt;
	}
	
	
	/**
	 * 查询会话队列
	 * @param mcsid
	 * @param userid
	 * @return
	 * @throws InterruptedException
	 */
	public List<YmtQueuesession> selectYmtQueuesession(Integer mcsid,Integer userid)
			throws InterruptedException {
		Map m=new HashMap<>();
		m.put("mcsid", mcsid);
		m.put("userid", userid);
		List<YmtQueuesession> ymt = new ArrayList<YmtQueuesession>();
		ymt = manage
				.getSelectResults(
						"com.ymttest.database.mapping.YmtSellerCSIMMapper.selectYmtQueuesession",
						m);
		manage.commit();
		return ymt;
	}
	/**
	 * 查询当前会话
	 * @param mcsid
	 * @param userid
	 * @return
	 * @throws InterruptedException
	 */
	public List<YmtCssession> selectYmtCssession(Integer mcsid,Integer userid)
			throws InterruptedException {
		Map m=new HashMap<>();
		m.put("mcsid", mcsid);
		m.put("userid", userid);
		List<YmtCssession> ymt = new ArrayList<YmtCssession>();
		ymt = manage
				.getSelectResults(
						"com.ymttest.database.mapping.YmtSellerCSIMMapper.selectYmtCssession",
						m);
		manage.commit();
		return ymt;
	}
	/**
	 * 查询当前会话
	 * @param mcsid
	 * @param userid
	 * @return
	 * @throws InterruptedException
	 */
	public List<YmtCssessionHistory> selectYmtCssessionHistory(Integer mcsid,Integer userid)
			throws InterruptedException {
		Map m=new HashMap<>();
		m.put("mcsid", mcsid);
		m.put("userid", userid);
		List<YmtCssessionHistory> ymt = new ArrayList<YmtCssessionHistory>();
		ymt = manage
				.getSelectResults(
						"com.ymttest.database.mapping.YmtSellerCSIMMapper.selectYmtCssessionHistory",
						m);
		manage.commit();
		return ymt;
	}
	/**
	 * 查询客服的全部话术
	 * @param csid
	 * @return [{CategoryId=3abd471faa634c1bab70698e9eb0d24d, icTitle=话术类别d3863, CSId=24635724, cTitle=null, id=null, cSort=null, icSort=1}]
	 * @throws InterruptedException
	 */
	public List<Map> selectIndividualdiscourseByCsid(Integer csid)
			throws InterruptedException {
		Map m=new HashMap<>();
		m.put("csid", csid);
		List<Map> ymt = new ArrayList<Map>();
		ymt = manage
				.getSelectResults(
						"com.ymttest.database.mapping.YmtSellerCSIMMapper.selectIndividualdiscourseByCsid",
						m);
		manage.commit();
		return ymt;
	}
	/**
	 * 修改最后消息时间
	 * @param id
	 * @param LastMessageTime
	 * @return
	 * @throws InterruptedException
	 */
	public int updateYmtCssessionLastMessageTime(String id,Date LastMessageTime)
			throws InterruptedException {
		Map m=new HashMap<>();
		m.put("id", id);
		m.put("LastMessageTime", LastMessageTime);
		int n = manage
				.update(
						"com.ymttest.database.mapping.YmtSellerCSIMMapper.updateYmtCssessionLastMessageTime",
						m);
		manage.commit();
		return n;
	}
	public static void main(String args[]) throws InterruptedException{
		new YmtSellerCSIMWapper().selectYmtOnlinecs(null, 24607502).forEach(ymtonline->{System.out.println(FormatUtil.beanToGSONString(ymtonline));});
	}
}
